package com.jwsoft.manager.core.gateway.controller;

import com.bifang.assistant.common.vo.BaseVO;
import com.bifang.engine.protect.core.annotation.NoSignCrypto;
import com.jwsoft.manager.core.integration.EduAddressTreeInitialIntegration;
import com.jwsoft.manager.common.vo.eduAddressTreeInitial.EduAddressTreeInitialVO;
import com.jwsoft.manager.common.vo.eduAddressTreeInitial.EduAddressTreeInitialKeyVO;
import com.jwsoft.manager.common.vo.eduAddressTreeInitial.EduAddressTreeInitialQueryVO;
import com.github.pagehelper.PageInfo;
import com.bifang.engine.assistant.core.domain.AppResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import com.bifang.engine.protect.core.annotation.Idempotent;
import org.springframework.validation.annotation.Validated;
import com.bifang.assistant.common.constants.Validators;

/**
 * 初始地址树表网关
 *
 * @author zhiyuan
 * @since 2024-01-09
 */
@RestController
@RequestMapping(value = "/doc/api")
@Tag(name = "初始地址树表", description = "初始地址树表")
public class EduAddressTreeInitialController {

    @Autowired
    public EduAddressTreeInitialIntegration eduAddressTreeInitialIntegration;

    @Operation(summary = "初始地址树表分页查询",description = "初始地址树表分页查询")
    @PostMapping(value = "/addressTreeInitial0001", produces = "application/json;charset=UTF-8")
    public AppResponse<PageInfo<EduAddressTreeInitialVO>> getList(@RequestBody @Validated EduAddressTreeInitialQueryVO vo) {
        return AppResponse.successData(eduAddressTreeInitialIntegration.getList(vo));
    }

    @Operation(summary = "初始地址树表根据主键查询详情",description = "初始地址树表根据主键查询详情")
    @PostMapping(value = "/addressTreeInitial0002", produces = "application/json;charset=UTF-8")
    public AppResponse<EduAddressTreeInitialVO> getById(@RequestBody @Validated EduAddressTreeInitialKeyVO vo) {
        return AppResponse.successData(eduAddressTreeInitialIntegration.getById(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "初始地址树表新增",description = "初始地址树表新增")
    @PostMapping(value = "/addressTreeInitial0004", produces = "application/json;charset=UTF-8")
    public AppResponse<EduAddressTreeInitialVO> add(@RequestBody @Validated(value = {Validators.Add.class}) EduAddressTreeInitialVO vo) {
        return AppResponse.successData(eduAddressTreeInitialIntegration.add(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "初始地址树表修改",description = "初始地址树表修改")
    @PostMapping(value = "/addressTreeInitial0005", produces = "application/json;charset=UTF-8")
    public AppResponse<EduAddressTreeInitialVO> edit(@RequestBody @Validated(value = {Validators.Edit.class}) EduAddressTreeInitialVO vo) {
        return AppResponse.successData(eduAddressTreeInitialIntegration.edit(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "初始地址树表删除",description = "初始地址树表删除")
    @PostMapping(value = "/addressTreeInitial0006", produces = "application/json;charset=UTF-8")
    public AppResponse del(@RequestBody @Validated EduAddressTreeInitialKeyVO vo) {
        eduAddressTreeInitialIntegration.del(vo);
        return AppResponse.successMsg("删除成功！");
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "初始地址树生成并初始化学区",description = "初始地址树生成并初始化学区")
    @PostMapping(value = "/addressTreeInitial0007", produces = "application/json;charset=UTF-8")
    @NoSignCrypto
    public AppResponse addressTreeCreate(@RequestBody @Validated EduAddressTreeInitialQueryVO vo) {
        eduAddressTreeInitialIntegration.addressTreeCreate(vo);
        return AppResponse.successMsg("解析成功！");
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "解析地址为树节点，不初始化学区",description = "解析地址为树节点，不初始化学区")
    @PostMapping(value = "/addressTreeInitial0008", produces = "application/json;charset=UTF-8")
    @NoSignCrypto
    public AppResponse parseAddressTree(@RequestBody @Validated EduAddressTreeInitialQueryVO vo) {
        eduAddressTreeInitialIntegration.parseAddressTree(vo);
        return AppResponse.successMsg("解析成功！");
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "清除地址解析锁缓存",description = "清除地址解析锁缓存")
    @PostMapping(value = "/addressTreeInitial0009", produces = "application/json;charset=UTF-8")
    @NoSignCrypto
    public AppResponse clearCache(@RequestBody @Validated BaseVO vo) {
        eduAddressTreeInitialIntegration.clearCache(vo);
        return AppResponse.successMsg("清除成功！");
    }
}
